package com.itheima.health.controller.admin;

import com.itheima.health.common.MessageConst;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.result.PageResult;
import com.itheima.health.result.QueryPageBean;
import com.itheima.health.result.Result;
import com.itheima.health.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/setmeal")
@Api(tags = "套餐相关接口")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 套餐新增
     * @param setmeal
     * @param checkGroupIds
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("套餐-新增")
    public Result add(@RequestBody Setmeal setmeal, @RequestParam(value = "checkgroupIds") List<Integer> checkGroupIds) {
        log.info("[套餐-新增]data:{} {}",setmeal, checkGroupIds);
        try {
            setmealService.add(setmeal,checkGroupIds);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConst.ADD_SETMEAL_FAIL);
        }
        return new Result(true, MessageConst.ADD_SETMEAL_SUCCESS);
    }

    /**
     * 套餐分页
     * @param queryPageBean
     * @return
     */
    @GetMapping("/findPage")
    @ApiOperation("套餐-分页")
    public Result findPage(QueryPageBean queryPageBean) {
        log.info("[套餐-分页查询]data:{}", queryPageBean);
        PageResult pageResult = setmealService.pageQuery(queryPageBean);
        return new Result(true,MessageConst.ACTION_SUCCESS,pageResult);
    }
}
